package com.sskj.gocoin.mine;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.gocoin.MyAppLication;
import com.sskj.gocoin.common.Constants;
import com.sskj.gocoin.m.HttpConfig;
import com.sskj.gocoin.m.bean.AseetListBean;
import com.sskj.gocoin.m.bean.HttpData;
import com.sskj.gocoin.m.bean.UserInfo;
import com.sskj.gocoin.m.http.JsonCallBack;
import com.sskj.gocoin.p.base.BasePresenter;
import com.sskj.gocoin.utils.SPUtils;


/**
 * @author Hey
 * Create at  2019/03/29
 */
class AssetManagerPresenter extends BasePresenter<AssetManagerActivity> {
    public void requestUserAssetList(boolean isFirst)   {
        OkGo.<HttpData<AseetListBean>>get(HttpConfig.BASE_URL + HttpConfig.ASEET_LIST)
                .params("mobile", MyAppLication.getMobile())
                .execute(new JsonCallBack<HttpData<AseetListBean>>(this, isFirst) {
                    @Override
                    protected void _onSuccess(Response<HttpData<AseetListBean>> response) {
                        HttpData<AseetListBean> httpListData = response.body();
                        if (httpListData.getCode() == 200) {
                            mView.onDataSuccess(httpListData.getData());
                        }
                    }
                });
    }

    public void upDateUserInfo(String mobile) {
        OkGo.<HttpData<UserInfo>>get(HttpConfig.BASE_URL + HttpConfig.GET_USER_INFO)
                .tag(mView)
                .execute(new JsonCallBack<HttpData<UserInfo>>(this, false) {
                    @Override
                    public void _onSuccess(Response<HttpData<UserInfo>> response) {
                        HttpData<UserInfo> httpData = response.body();
                        if (httpData.getCode() == 200) {
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_IS_SHOP, httpData.getData().is_shop);
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_REALNAME_STATUS, httpData.getData().getAuthentication());
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_PAY_SIZE, httpData.getData().getPay_list());

                            if (httpData.getData().getName() != null) {
                                SPUtils.put(MyAppLication.getApplication(), Constants.SP_REALNAME, httpData.getData().getName());
                            }
                            if (httpData.getData().getCard_id() != null) {
                                SPUtils.put(MyAppLication.getApplication(), Constants.SP_IDCORD, httpData.getData().getCard_id());
                            }
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_JGCODE, httpData.getData().getJigou_code());
                            SPUtils.put(MyAppLication.getApplication(), Constants.SP_USDT, httpData.getData().getUsdt());

                            mView.updateUserInfo(httpData.getData());
                        }
                    }
                });
    }
}
